﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using crm_dal.Objects;
using crm_library.Javascript;

namespace crm_web.DataPages
{
    public partial class CreateUser : System.Web.UI.Page
    {
        User displayUser;

        protected void Page_Load(object sender, EventArgs e)
        {
            displayUser = new User(Convert.ToInt32(HttpContext.Current.Session["Selection"]));
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            string error = "";
            try
            {

                displayUser.FirstName = txtFirstName.Text.Trim();
                displayUser.LastName = txtLastName.Text.Trim();
                displayUser.LoginName = txtLoginName.Text.Trim();
                displayUser.IsAdmin = chkIsAdmin.Checked;
                displayUser.IsMgr = chkIsMgr.Checked;
                displayUser.IsCSR = chkIsCSR.Checked;
                displayUser.IsSA = chkIsSA.Checked;

                displayUser.Create();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            if (!String.IsNullOrWhiteSpace(error))
            {
                Alert.Show(error, Alert.AlertMessageType.Error);
            }
            else
            {
                Alert.Show("create succeeded", Alert.AlertMessageType.Message, "/DataPages/Users.aspx");
            }

        }
    }
}